package com.son.hotel.controller;

import com.son.hotel.common.ErrorCode;
import com.son.hotel.common.Result;
import com.son.hotel.domain.AccommodationInfo;
import com.son.hotel.domain.Customers;
import com.son.hotel.execption.BusinessException;
import com.son.hotel.service.AccommodationInfoService;
import com.son.hotel.service.CustomersService;
import com.son.hotel.vo.CustomAndRoomInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/menu")
public class AccommodationInfoController {

    @Autowired
    private CustomersService customersService;

    @Autowired
    private AccommodationInfoService accommodationInfoService;
    /**
     * 预定房间：顾客表(登记这个人的基本信息)、住宿表(登记住宿信息)、房间的类型表(数量减一)、房间表(修改状态)
     * @return
     */
    @PostMapping("/book/room")
    public Result<Boolean> bookRoom(@RequestBody CustomAndRoomInfo customAndRoomInfo){
        log.info("住房登记信息:{}",customAndRoomInfo);
        //1.将信息添加到用户表中
        int res = customersService.addCustom(customAndRoomInfo);
        if (res <= 0){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"插入失败");
        }
        //2.
        accommodationInfoService.addAccommodationInfo(customAndRoomInfo);
        return Result.success("200",true);
    }
}
